package com.neusoft.elm.util;


import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class DBUtil {

	private static final String URL ="jdbc:mysql://124.70.85.102:3306/elm_admin?sslmode=require";
	private static final String DRIVER ="com.mysql.cj.jdbc.Driver";
	private static final String USERNAME ="root";
	private static final String PASSWORD ="Elm123456";

	//获取Connection
	public static Connection getConnection() {    												//远程数据库连接检测
		Connection con =null;
		try {
			Class.forName(DRIVER);
			con = DriverManager.getConnection(URL,USERNAME,PASSWORD);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return con;
	}
	
	//关闭资源
	public static void close(ResultSet rs,PreparedStatement pst,Connection con) {
		if(rs!=null) {
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if(pst!=null) {
			try {
				pst.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if(con!=null) {
			try {
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}